Skip to content

feat: CI link validation for MDX content#190

Merged
ErnestM1234 merged 5 commits intomainfrom
ci/link-validation
Mar 31, 2026
Merged

feat: CI link validation for MDX content#190
ErnestM1234 merged 5 commits intomainfrom
ci/link-validation

Conversation

@moss-bryophyta
Copy link
Copy Markdown
Collaborator

Summary

Adds a TypeScript-based link validator that runs in CI on every PR.

What it validates

  • Internal links (starting with /) resolve to actual files
  • Anchor fragments (#heading) exist in the target file
  • Same-page anchors validated against current file headings
  • Custom heading IDs via [#id] syntax (e.g. ## My Heading [#custom-id])
  • Locale-optional paths/docs/next/intro and /en-US/docs/next/intro both valid
  • Template placeholder links — expands __DOCS_PATH__ etc. for next/react/react-native and validates each

Files

  • scripts/validate-links.ts — main validator (mdast AST parser + github-slugger)
  • scripts/test-validate-links.ts — unit tests
  • scripts/package.json + lockfile + .gitignore
  • .github/workflows/validate.yml — added validate-links job

Note

There are 33 pre-existing broken links in the current content (missing files in react-native, empty generated pages, stale anchors). These are real issues, not false positives. CI will flag them on this PR — they can be fixed in a follow-up or in this PR before merge.

- TypeScript link validator using mdast AST parser
- Validates internal links resolve to actual files
- Validates anchor fragments (#heading) exist in target files
- Supports custom heading IDs via [#id] syntax
- Handles locale-optional links (middleware auto-fills locale)
- Validates docs-templates/ by expanding placeholders for each library
- Clear error output grouped by file with line numbers
- Unit tests for core utilities
- Added validate-links job to CI workflow
@moss-bryophyta moss-bryophyta requested a review from a team as a code owner March 31, 2026 02:11
- Add permissions: contents: read to validate.yml (security bot comment)
- Fix broken cross-references in templates to pages that only exist for
  some platforms (with-gt-config, get-default-locale, get-locale-direction,
  get-locale-properties, get-locales, get-region, get-messages, guides/rtl)
- Fix broken #decodemsg anchor → #getting-original-strings-with-decodemsg
- Fix broken #privacy anchor → #privacy-and-security
- Fix bare /docs links in blog/plurals.mdx → /docs/react and /docs/next
The server-side get-* helpers (getLocaleDirection, getLocaleProperties,
getLocales, getRegion) are Next.js-only. Moved from shared templates to
next-specific docs and removed incorrect react stubs/meta references.
Templates are shared across next/react/react-native. Server-side functions
like getLocales, getLocaleDirection, getLocaleProperties, getRegion, and
getMessages are next-only, so references to them don't belong in templates.
@ErnestM1234 ErnestM1234 enabled auto-merge (squash) March 31, 2026 02:40
@ErnestM1234 ErnestM1234 merged commit 62e36bf into main Mar 31, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants